/*
' Copyright (c) 2011  DotNetNuke Corporation
'  All rights reserved.
' 
' THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
' TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
' THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
' CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
' DEALINGS IN THE SOFTWARE.
' 
*/

using System;
using DotNetNuke.Services.Exceptions;
using DotNetNuke.Entities.Modules;
using DotNetNuke.Entities.Modules.Actions;
using DotNetNuke.Services.Localization;
using DotNetNuke.Security;
using DotNetNuke.Services.ClientCapability;


namespace DotNetNuke.Modules.FB_FanGate {

    /// -----------------------------------------------------------------------------
    /// <summary>
    /// The ViewFB_FanGate class displays the content
    /// </summary>
    /// -----------------------------------------------------------------------------
    public partial class View : FB_FanGateModuleBase, IActionable {

        #region Event Handlers

        override protected void OnInit(EventArgs e) {
            InitializeComponent();
            base.OnInit(e);
        }

        private void InitializeComponent() {
            this.Load += new System.EventHandler(this.Page_Load);
        }


        /// -----------------------------------------------------------------------------
        /// <summary>
        /// Page_Load runs when the control is loaded
        /// </summary>
        /// -----------------------------------------------------------------------------
        private void Page_Load(object sender, System.EventArgs e) {
            try {
                IClientCapability device = ClientCapabilityProvider.CurrentClientCapability;
                bool isLiked = false;
                string IsFanText = string.Empty;
                if (Settings.ContainsKey("IsFanText")) {
                    IsFanText = Settings["IsFanText"].ToString();
                }
                string NotFanText = string.Empty;
                if (Settings.ContainsKey("NotFanText")) {
                    NotFanText = Settings["NotFanText"].ToString();
                }
                string fbKey = string.Empty;
                if (!Settings.ContainsKey("FBAPPKEY")) {
                    litOutput.Text = "Please setup you Facebook Secret Key under module settings.";
                } else {
                    fbKey = Settings["FBAPPKEY"].ToString();
                }
                if (device.FacebookRequest != null && !String.IsNullOrEmpty(fbKey)) {
                    device.FacebookRequest.OauthToken = fbKey;
                    isLiked = device.FacebookRequest.PageLiked;
                }
                if (isLiked) {
                    litOutput.Text = IsFanText;
                } else {
                    litOutput.Text = NotFanText;
                }

            } catch (Exception exc) //Module failed to load
            {
                Exceptions.ProcessModuleLoadException(this, exc);
            }
        }

        #endregion

        #region Optional Interfaces

        public ModuleActionCollection ModuleActions {
            get {
                ModuleActionCollection Actions = new ModuleActionCollection();
                Actions.Add(GetNextActionID(), Localization.GetString("EditModule", this.LocalResourceFile), "", "", "", EditUrl(), false, SecurityAccessLevel.Edit, true, false);
                return Actions;
            }
        }

        #endregion

    }

}
